﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccessLayer.Appointments;
using DataAccessLayer.Patients;
using ModelLayer.Appointments;
using System.Data;

namespace BussinesLayer.Appointments
{
    public class AppointmentRegistrationController
    {
        AppointmentDataAccess appointment = new AppointmentDataAccess();

        public static bool isNewAppointment = false;
        public static int logTime = 0;
        public static string nameLocation = null;
        public static string accessionNumberSelected = null;

        public void CancelVisit(string AccessionNumber, string CancelingPurpose, string CancelReason)
        {
            appointment.CancelVisit(AccessionNumber, CancelingPurpose, CancelReason);
        }

        // not used by MVP
        public string GetNameByDescriptionLocation(string description)
        {
            return appointment.GetNameByDescription(description);
        }

        public string GetPatientOID(string idDocumentNumber, string familyName, string givenName)
        {
            return PatientsDataAccess.GetPatientOID(idDocumentNumber, familyName, givenName);
        }

        public void CreateVisit(Guid patientOID, string visitNumberId, DateTime admitTime, DateTime dischargeTime, string accessionNumber, string purpose, bool isAppointment)
        {
            Visit visit = new Visit();
            visit = Visit.NewVisit(patientOID, visitNumberId, admitTime, dischargeTime, accessionNumber, purpose, isAppointment);
            appointment.InsertNewVisit(visit);
        }

        public void ModifyAppointment(Guid patientOID, string visitNumberId, DateTime admitTime, DateTime dischargeTime, string accessionNumber, string purpose, bool isAppointment)
        {
            Visit visit = new Visit();
            visit = Visit.NewVisit(patientOID, visitNumberId, admitTime, dischargeTime, accessionNumber, purpose, isAppointment);
            appointment.ModifyAppointment(accessionNumber, visit);
        }
        
        public List<VisitModelView> SelectAppointments(DateTime from, DateTime to)
        {
            //Añadimos un dia mas para que nos muestre la consulta Desde la fecha asignada hasta la fecha q indicamos +1
            return appointment.SelectAppointments(from, to);
        }

        public VisitModelView GetAppointment(string accessionNumber)
        {
            return appointment.GetAppointment(accessionNumber);
        }
    }
}
